
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 菜单界面
 */
public class MenuPanel extends JPanel implements ActionListener {
    private JButton buttonFind;
    private JButton buttonGet;
    private JButton buttonModify;
    private JButton buttonSave;
    private JButton buttonOff;
    private JButton buttonTransfer;
    private Atmtest frame;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

    }

    public MenuPanel(Atmtest frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        buttonFind = new JButton(Util.getIcon("/img/buttonFind.jpg"));
        buttonFind.setBounds(900, 50, 100, 50);
        this.add(buttonFind);
        buttonFind.addActionListener(this);

        buttonGet = new JButton(Util.getIcon("/img/buttonGet.jpg"));
        buttonGet.setBounds(900, 120, 100, 50);
        this.add(buttonGet);
        buttonGet.addActionListener(this);

        buttonModify = new JButton(Util.getIcon("/img/buttonModify.jpg"));
        buttonModify.setBounds(900, 190, 100, 50);
        this.add(buttonModify);
        buttonModify.addActionListener(this);

        buttonSave = new JButton(Util.getIcon("/img/buttonSave.jpg"));
        buttonSave.setBounds(900, 260, 100, 50);
        this.add(buttonSave);
        buttonSave.addActionListener(this);

        buttonOff = new JButton(Util.getIcon("/img/buttonOff.jpg"));
        buttonOff.setBounds(900, 330, 100, 50);
        this.add(buttonOff);
        buttonOff.addActionListener(this);

        buttonTransfer = new JButton("转账");
        buttonTransfer.setBounds(900, 400, 100, 50);
        this.add(buttonTransfer);
        buttonTransfer.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (buttonOff == e.getSource()) {
            frame.switchPanel("login");
        }
        if (buttonFind == e.getSource()) {
            frame.getFind().setname();
            frame.switchPanel("find");
        }
        if (buttonGet == e.getSource()) {
            frame.getGet().setmoney();
            frame.switchPanel("get");
        }
        if (buttonModify == e.getSource()) {
            frame.getModify().getmima();
            frame.switchPanel("modify");
        }
        if (buttonSave == e.getSource()) {
            frame.getSave().setMoney();
            frame.switchPanel("save");
        }
        if (buttonTransfer == e.getSource()) {
           frame.getTransfer().setMoney();
            frame.switchPanel("transfer");
        }
    }
}
